import { http } from '@/utils/request'
import type {
  JobListParamsType,
  JobLogListParamsType,
  JobLogType,
  JobType,
  JobWriteParamsType
} from './model'

/**
 * 获取任务列表
 * @param params 任务列表参数
 */
export const getJobListAPI = (params: JobListParamsType) => {
  return http.request<PageResult<JobType>>('get', '/monitor/job', { params })
}

/**
 * 添加任务
 * @param data 任务参数
 */
export const addJobAPI = (data: JobWriteParamsType) => {
  return http.request<JobType>('post', '/monitor/job', { data })
}

/**
 * 更新任务
 * @param id 任务ID
 * @param data 任务参数
 */
export const updateJobAPI = (id: number, data: JobWriteParamsType) => {
  return http.request<JobType>('put', `/monitor/job/${id}`, { data })
}

/**
 * 更改任务状态
 * @param id 任务ID
 * @param status
 */
export const changeJobStatusAPI = (id: number, status: number) => {
  return http.request<boolean>('put', `/monitor/job/changeStatus/${id}`, {
    data: {
      status
    }
  })
}

/**
 * 批量删除任务
 * @param ids 任务ID
 */
export const deleteJobAPI = (ids: number[]) => {
  return http.request<JobType>('delete', `/monitor/job/batchDelete/${ids.join(',')}`)
}

/**
 * 立即执行任务
 * @param id 任务ID
 */
export const runJobAPI = (id: number) => {
  return http.request<void>('post', `/monitor/job/run/${id}`)
}

/**
 * 分页获取定时任务调度日志列表
 * @param params
 */
export const getJobLogListAPI = (params: JobLogListParamsType) => {
  return http.request<PageResult<JobLogType>>('get', '/monitor/jobLog', { params })
}
